<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">

  <!-- PACE Progress Bar START -->
  
    <script src="https://raw.githubusercontent.com/HubSpot/pace/v1.0.2/pace.min.js"></script>
    <link rel="stylesheet" href="https://github.com/HubSpot/pace/raw/master/themes/orange/pace-theme-flash.css">
  
  

  <!-- PACE Progress Bar START -->

  
  <title>docker常用命令大全 | FunGa技术札记</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  <meta name="keywords" content="docker">
  
  
  
  
  <meta name="description" content="容器生命周期管理rundocker run ：创建一个新的容器并运行一个命令 语法docker run [OPTIONS] IMAGE [COMMAND] [ARG...]">
<meta name="keywords" content="docker">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker常用命令大全">
<meta property="og:url" content="funga.cn/2017/12/17/docker-cmd/index.html">
<meta property="og:site_name" content="FunGa技术札记">
<meta property="og:description" content="容器生命周期管理rundocker run ：创建一个新的容器并运行一个命令 语法docker run [OPTIONS] IMAGE [COMMAND] [ARG...]">
<meta property="og:locale" content="default">
<meta property="og:image" content="http://funga.oss-cn-beijing.aliyuncs.com/images/docekr.jpg">
<meta property="og:updated_time" content="2019-01-05T07:52:57.281Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Docker常用命令大全">
<meta name="twitter:description" content="容器生命周期管理rundocker run ：创建一个新的容器并运行一个命令 语法docker run [OPTIONS] IMAGE [COMMAND] [ARG...]">
<meta name="twitter:image" content="http://funga.oss-cn-beijing.aliyuncs.com/images/docekr.jpg">
  
    <link rel="alternate" href="/atom.xml" title="FunGa技术札记" type="application/atom+xml">
  
  <link rel="icon" href="/css/images/favicon.ico">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <link href="https://cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/9749f0/00000000000000000001008f/27/l?subset_id=2&fvd=n5) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/90cf9f/000000000000000000010091/27/l?subset_id=2&fvd=n7) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/8a5494/000000000000000000013365/27/l?subset_id=2&fvd=n4) format("woff2");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/d337d8/000000000000000000010095/27/l?subset_id=2&fvd=i4) format("woff2");font-weight:400;font-style:italic;}</style>
    
  <link rel="stylesheet" id="athemes-headings-fonts-css" href="//fonts.googleapis.com/css?family=Yanone+Kaffeesatz%3A200%2C300%2C400%2C700&amp;ver=4.6.1" type="text/css" media="all">
  <link rel="stylesheet" href="/css/style.css">

  <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
  <link rel="stylesheet" href="/css/hiero.css">
  <link rel="stylesheet" href="/css/glyphs.css">
  
    <link rel="stylesheet" href="/css/vdonate.css">
  

  <!-- Custom CSS -->
  <link rel="stylesheet" href="/css/my.css">
  <!-- Google Adsense -->
  
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>
</html>
<script>
var themeMenus = {};

  themeMenus["/"] = "Home"; 

  themeMenus["/archives"] = "Archives"; 

  themeMenus["/categories"] = "Categories"; 

  themeMenus["/tags"] = "Tags"; 

  themeMenus["/about"] = "About"; 

</script>


  <body data-spy="scroll" data-target="#toc" data-offset="50">


  <header id="allheader" class="site-header" role="banner">
  <div class="clearfix container">
      <div class="site-branding">

          <h1 class="site-title">
            
              <a href="/" title="FunGa技术札记" rel="home"> FunGa技术札记 </a>
            
          </h1>

          
            
          <nav id="main-navigation" class="main-navigation" role="navigation">
            <a class="nav-open">Menu</a>
            <a class="nav-close">Close</a>
            <div class="clearfix sf-menu">

              <ul id="main-nav" class="nmenu sf-js-enabled">
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/">Home</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/archives">Archives</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/categories">Categories</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/tags">Tags</a> </li>
                    
                      <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-1663"> <a class="" href="/about">About</a> </li>
                    
              </ul>
            </div>
          </nav>


      </div>
  </div>
</header>




  <div id="container">
    <div id="wrap">
            
      <div id="content" class="outer">
        
          <section id="main" style="float:none;"><article id="post-docker-cmd" style="width: 66%; float:left;" class="article article-type-post" itemscope="" itemprop="blogPost">
  <div id="articleInner" class="clearfix post-1016 post type-post status-publish format-standard has-post-thumbnail hentry category-template-2 category-uncategorized tag-codex tag-edge-case tag-featured-image tag-image tag-template">
    
<div class="article-gallery">
  <div class="article-gallery-photos">
    
      <a class="article-gallery-img fancybox" href="http://funga.oss-cn-beijing.aliyuncs.com/images/docekr.jpg" rel="gallery_cjqujn6yw002y8zvnrkntoy6j">
        <img src="http://funga.oss-cn-beijing.aliyuncs.com/images/docekr.jpg" itemprop="image">
      </a>
    
  </div>
</div>

    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      Docker常用命令大全
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	Posted on <a href="/2017/12/17/docker-cmd/" class="article-date">
	  <time datetime="2017-12-17T04:39:17.000Z" itemprop="datePublished">December 17, 2017</time>
	</a>

      
	<span id="busuanzi_container_page_pv">
	  本文总阅读量<span id="busuanzi_value_page_pv"></span>次
	</span>

    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="容器生命周期管理"><a href="#容器生命周期管理" class="headerlink" title="容器生命周期管理"></a>容器生命周期管理</h2><h3 id="run"><a href="#run" class="headerlink" title="run"></a>run</h3><p><code>docker run</code> ：创建一个新的容器并运行一个命令</p>
<h4 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
</code></pre>
<a id="more"></a>
<p><strong>OPTIONS说明</strong>：</p>
<ul>
<li><p>-a stdin: 指定标准输入输出内容类型，可选 STDIN/STDOUT/STDERR 三项；</p>
</li>
<li><p>-d: 后台运行容器，并返回容器ID；</p>
</li>
<li><p>-i: 以交互模式运行容器，通常与 -t 同时使用；</p>
</li>
<li><p>-p: 端口映射，格式为：主机(宿主)端口:容器端口</p>
</li>
<li><p>-t: 为容器重新分配一个伪输入终端，通常与 -i 同时使用；</p>
</li>
<li><p>–name=”nginx-lb”: 为容器指定一个名称；</p>
</li>
<li><p>–dns 8.8.8.8: 指定容器使用的DNS服务器，默认和宿主一致；</p>
</li>
<li><p>–dns-search example.com: 指定容器DNS搜索域名，默认和宿主一致；</p>
</li>
<li><p>-h “mars”: 指定容器的hostname；</p>
</li>
<li><p>-e username=”ritchie”: 设置环境变量；</p>
</li>
<li><p>–env-file=[]: 从指定文件读入环境变量；</p>
</li>
<li><p>–cpuset=”0-2” or –cpuset=”0,1,2”: 绑定容器到指定CPU运行；</p>
</li>
<li><p>-m :设置容器使用内存最大值；</p>
</li>
<li><p>–net=”bridge”: 指定容器的网络连接类型，支持 bridge/host/none/container: 四种类型；</p>
</li>
<li><p>–link=[]: 添加链接到另一个容器；</p>
</li>
<li><p>–expose=[]: 开放一个端口或一组端口；</p>
</li>
</ul>
<h4 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h4><p><em>使用docker镜像nginx:latest以后台模式启动一个容器,并将容器命名为mynginx。</em></p>
<pre class=" language-shell"><code class="language-shell">docker run --name mynginx -d nginx:latest
</code></pre>
<p><em>使用镜像nginx:latest以后台模式启动一个容器,并将容器的80端口映射到主机随机端口。</em></p>
<pre class=" language-shell"><code class="language-shell">docker run -P -d nginx:latest

</code></pre>
<p><em>使用镜像 nginx:latest，以后台模式启动一个容器,将容器的 80 端口映射到主机的 80 端口,主机的目录 /data 映射到容器的 /data。</em></p>
<pre class=" language-shell"><code class="language-shell">docker run -p 80:80 -v /data:/data -d nginx:latest
</code></pre>
<p><em>绑定容器的 8080 端口，并将其映射到本地主机 127.0.0.1 的 80 端口上。</em></p>
<pre class=" language-shell"><code class="language-shell">$ docker run -p 127.0.0.1:80:8080/tcp ubuntu bash
</code></pre>
<p><em>使用镜像nginx:latest以交互模式启动一个容器,在容器内执行/bin/bash命令。</em></p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker run -it nginx:latest /bin/bash
root@b8573233d675:/# 
</code></pre>
<h3 id="start-stop-restart"><a href="#start-stop-restart" class="headerlink" title="start/stop/restart"></a>start/stop/restart</h3><p><code>docker start</code> :启动一个或多个已经被停止的容器</p>
<p><code>docker stop</code> :停止一个运行中的容器</p>
<p><code>docker restart</code> :重启容器</p>
<h4 id="语法-1"><a href="#语法-1" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker start [OPTIONS] CONTAINER [CONTAINER...]
docker stop [OPTIONS] CONTAINER [CONTAINER...]
docker restart [OPTIONS] CONTAINER [CONTAINER...]
</code></pre>
<h4 id="实例-1"><a href="#实例-1" class="headerlink" title="实例"></a>实例</h4><p><em>启动已被停止的容器myfunga</em></p>
<pre class=" language-shell"><code class="language-shell">docker start myfunga
</code></pre>
<p><em>停止运行中的容器myfunga</em></p>
<pre class=" language-shell"><code class="language-shell">docker stop myfunga
</code></pre>
<p><em>重启容器myfunga</em></p>
<pre class=" language-shell"><code class="language-shell">docker restart myfunga
</code></pre>
<h3 id="kill"><a href="#kill" class="headerlink" title="kill"></a>kill</h3><p><code>docker kill</code> :杀掉一个运行中的容器。</p>
<h4 id="语法-2"><a href="#语法-2" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker kill [OPTIONS] CONTAINER [CONTAINER...]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li>-s :向容器发送一个信号</li>
</ul>
<h4 id="实例-2"><a href="#实例-2" class="headerlink" title="实例"></a>实例</h4><p><em>杀掉运行中的容器mynginx</em></p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker kill -s KILL mynginx
mynginx
</code></pre>
<h3 id="rm"><a href="#rm" class="headerlink" title="rm"></a>rm</h3><p><code>docker rm</code> ：删除一个或多少容器</p>
<h4 id="语法-3"><a href="#语法-3" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker rm [OPTIONS] CONTAINER [CONTAINER...]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li><p>-f :通过SIGKILL信号强制删除一个运行中的容器</p>
</li>
<li><p>-l :移除容器间的网络连接，而非容器本身</p>
</li>
<li><p>-v :-v 删除与容器关联的卷</p>
</li>
</ul>
<h4 id="实例-3"><a href="#实例-3" class="headerlink" title="实例"></a>实例</h4><p><em>强制删除容器db01、db02</em></p>
<pre class=" language-shell"><code class="language-shell">docker rm -f db01 db02
</code></pre>
<p><em>移除容器nginx01对容器db01的连接，连接名db</em></p>
<pre class=" language-shell"><code class="language-shell">docker rm -l db 
</code></pre>
<p><em>删除容器nginx01,并删除容器挂载的数据卷</em></p>
<pre class=" language-shell"><code class="language-shell">docker rm -v nginx01
</code></pre>
<h3 id="pause-unpause"><a href="#pause-unpause" class="headerlink" title="pause/unpause"></a>pause/unpause</h3><p><code>docker pause</code> :暂停容器中所有的进程。</p>
<p><code>docker unpause</code> :恢复容器中所有的进程。</p>
<h4 id="语法-4"><a href="#语法-4" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker pause [OPTIONS] CONTAINER [CONTAINER...]
docker unpause [OPTIONS] CONTAINER [CONTAINER...]
</code></pre>
<h4 id="实例-4"><a href="#实例-4" class="headerlink" title="实例"></a>实例</h4><p><em>暂停数据库容器db01提供服务。</em></p>
<pre class=" language-shell"><code class="language-shell">docker pause db01
</code></pre>
<p><em>恢复数据库容器db01提供服务。</em></p>
<pre class=" language-shell"><code class="language-shell">docker unpause db01
</code></pre>
<h3 id="create"><a href="#create" class="headerlink" title="create"></a>create</h3><p><code>docker create</code> ：创建一个新的容器但不启动它</p>
<p>用法同 <code>docker run</code></p>
<h4 id="语法-5"><a href="#语法-5" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
</code></pre>
<p>语法同 <code>docker run</code></p>
<h4 id="实例-5"><a href="#实例-5" class="headerlink" title="实例"></a>实例</h4><p><em>使用docker镜像nginx:latest创建一个容器,并将容器命名为myfunga</em></p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker create  --name myfunga  nginx:latest      
09b93464c2f75b7b69f83d56a9cfc23ceb50a48a9db7652ee4c27e3e2cb1961f
</code></pre>
<h3 id="exec"><a href="#exec" class="headerlink" title="exec"></a>exec</h3><p><code>docker exec</code> ：在运行的容器中执行命令</p>
<h4 id="语法-6"><a href="#语法-6" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li><p>-d :分离模式: 在后台运行</p>
</li>
<li><p>-i :即使没有附加也保持STDIN 打开</p>
</li>
<li><p>-t :分配一个伪终端</p>
</li>
</ul>
<h4 id="实例-6"><a href="#实例-6" class="headerlink" title="实例"></a>实例</h4><p><em>在容器mynginx中以交互模式执行容器内<code>/root/funga.sh</code>脚本</em></p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker exec -it mynginx /bin/sh /root/funga.sh
http://www.funga.cn/
</code></pre>
<p><em>在容器mynginx中开启一个交互模式的终端</em></p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker exec -i -t  mynginx /bin/bash
root@b1a0703e41e7:/#
</code></pre>
<h2 id="容器操作"><a href="#容器操作" class="headerlink" title="容器操作"></a>容器操作</h2><h3 id="ps"><a href="#ps" class="headerlink" title="ps"></a>ps</h3><p><code>docker ps</code> : 列出容器</p>
<h4 id="语法-7"><a href="#语法-7" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker ps [OPTIONS]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li><p>-a :显示所有的容器，包括未运行的。</p>
</li>
<li><p>-f :根据条件过滤显示的内容。</p>
</li>
<li><p>–format :指定返回值的模板文件。</p>
</li>
<li><p>-l :显示最近创建的容器。</p>
</li>
<li><p>-n :列出最近创建的n个容器。</p>
</li>
<li><p>–no-trunc :不截断输出。</p>
</li>
<li><p>-q :静默模式，只显示容器编号。</p>
</li>
<li><p>-s :显示总的文件大小。</p>
</li>
</ul>
<h4 id="实例-7"><a href="#实例-7" class="headerlink" title="实例"></a>实例</h4><p><em>列出所有在运行的容器信息。</em></p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker ps
CONTAINER ID   IMAGE          COMMAND                ...  PORTS                    NAMES
09b93464c2f7   nginx:latest   "nginx -g 'daemon off" ...  80/tcp, 443/tcp          myfunga
96f7f14e99ab   mysql:5.6      "docker-entrypoint.sh" ...  0.0.0.0:3306->3306/tcp   mymysql
</code></pre>
<p><em>列出最近创建的5个容器信息。</em></p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker ps -n 5
CONTAINER ID        IMAGE               COMMAND                   CREATED           
09b93464c2f7        nginx:latest        "nginx -g 'daemon off"    2 days ago   ...     
b8573233d675        nginx:latest        "/bin/bash"               2 days ago   ...     
b1a0703e41e7        nginx:latest        "nginx -g 'daemon off"    2 days ago   ...    
f46fb1dec520        5c6e1090e771        "/bin/sh -c 'set -x \t"   2 days ago   ...   
a63b4a5597de        860c279d2fec        "bash"                    2 days ago   ...
</code></pre>
<p><em>列出所有创建的容器ID。</em></p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker ps -a -q
09b93464c2f7
b8573233d675
b1a0703e41e7
f46fb1dec520
a63b4a5597de
6a4aa42e947b
de7bb36e7968
43a432b73776
664a8ab1a585
ba52eb632bbd
...
</code></pre>
<h3 id="inspect"><a href="#inspect" class="headerlink" title="inspect"></a>inspect</h3><p><code>docker inspect</code> : 获取容器/镜像的元数据。</p>
<h4 id="语法-8"><a href="#语法-8" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker inspect [OPTIONS] NAME|ID [NAME|ID...]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li><p>-f :指定返回值的模板文件。</p>
</li>
<li><p>–s :显示总的文件大小。</p>
</li>
<li><p>–type :为指定类型返回JSON。</p>
</li>
</ul>
<h4 id="实例-8"><a href="#实例-8" class="headerlink" title="实例"></a>实例</h4><p><em>获取镜像mysql:5.6的元信息。</em></p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker inspect mysql:5.6
[
    {
        "Id": "sha256:2c0964ec182ae9a045f866bbc2553087f6e42bfc16074a74fb820af235f070ec",
        "RepoTags": [
            "mysql:5.6"
        ],
        "RepoDigests": [],
        "Parent": "",
        "Comment": "",
        "Created": "2016-05-24T04:01:41.168371815Z",
        "Container": "e0924bc460ff97787f34610115e9363e6363b30b8efa406e28eb495ab199ca54",
        "ContainerConfig": {
            "Hostname": "b0cf605c7757",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3306/tcp": {}
            },
            ...
</code></pre>
<p><em>获取正在运行的容器mymysql的 IP。</em></p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mymysql
172.17.0.3
</code></pre>
<h3 id="top"><a href="#top" class="headerlink" title="top"></a>top</h3><p><code>docker top</code> :查看容器中运行的进程信息，支持 ps 命令参数。</p>
<h4 id="语法-9"><a href="#语法-9" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker top [OPTIONS] CONTAINER [ps OPTIONS]
</code></pre>
<p>容器运行时不一定有/bin/bash终端来交互执行top命令，而且容器还不一定有top命令，可以使用docker top来实现查看container中正在运行的进程。</p>
<h4 id="实例-9"><a href="#实例-9" class="headerlink" title="实例"></a>实例</h4><p>查看容器mymysql的进程信息。</p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~/mysql$ docker top mymysql
UID    PID    PPID    C      STIME   TTY  TIME       CMD
999    40347  40331   18     00:58   ?    00:00:02   mysqld
</code></pre>
<p>查看所有运行容器的进程信息。</p>
<pre class=" language-shell"><code class="language-shell">for i in  `docker ps |grep Up|awk '{print $1}'`;do echo \ &&docker top $i; done
</code></pre>
<h3 id="attach"><a href="#attach" class="headerlink" title="attach"></a>attach</h3><p>docker attach :连接到正在运行中的容器。</p>
<h4 id="语法-10"><a href="#语法-10" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker attach [OPTIONS] CONTAINER
</code></pre>
<p>要attach上去的容器必须正在运行，可以同时连接上同一个container来共享屏幕（与screen命令的attach类似）。</p>
<p>官方文档中说attach后可以通过<code>CTRL-C</code>来detach，但实际上经过我的测试，如果container当前在运行bash，CTRL-C自然是当前行的输入，没有退出；如果container当前正在前台运行进程，如输出nginx的access.log日志，CTRL-C不仅会导致退出容器，而且还stop了。这不是我们想要的，detach的意思按理应该是脱离容器终端，但容器依然运行。好在attach是可以带上–sig-proxy=false来确保CTRL-D或CTRL-C不会关闭容器。</p>
<h4 id="实例-10"><a href="#实例-10" class="headerlink" title="实例"></a>实例</h4><p>容器mynginx将访问日志指到标准输出，连接到容器查看访问信息。</p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker attach --sig-proxy=false mynginx
192.168.239.1 - - [10/Jul/2016:16:54:26 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36" "-"
</code></pre>
<h3 id="events"><a href="#events" class="headerlink" title="events"></a>events</h3><p><code>docker events</code> : 从服务器获取实时事件</p>
<h4 id="语法-11"><a href="#语法-11" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker events [OPTIONS]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li><p>-f ：根据条件过滤事件；</p>
</li>
<li><p>–since ：从指定的时间戳后显示所有事件;</p>
</li>
</ul>
<p>—until ：流水时间显示到指定的时间为止；</p>
<h4 id="实例-11"><a href="#实例-11" class="headerlink" title="实例"></a>实例</h4><p>显示docker 2016年7月1日后的所有事件。</p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~/mysql$ docker events  --since="1467302400"
2016-07-08T19:44:54.501277677+08:00 network connect 66f958fd13dc4314ad20034e576d5c5eba72e0849dcc38ad9e8436314a4149d4 (container=b8573233d675705df8c89796a2c2687cd8e36e03646457a15fb51022db440e64, name=bridge, type=bridge)
2016-07-08T19:44:54.723876221+08:00 container start b8573233d675705df8c89796a2c2687cd8e36e03646457a15fb51022db440e64 (image=nginx:latest, name=elegant_albattani)
2016-07-08T19:44:54.726110498+08:00 container resize b8573233d675705df8c89796a2c2687cd8e36e03646457a15fb51022db440e64 (height=39, image=nginx:latest, name=elegant_albattani, width=167)
2016-07-08T19:46:22.137250899+08:00 container die b8573233d675705df8c89796a2c2687cd8e36e03646457a15fb51022db440e64 (exitCode=0, image=nginx:latest, name=elegant_albattani)
...
</code></pre>
<p>显示docker 镜像为mysql:5.6 2016年7月1日后的相关事件。</p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~/mysql$ docker events -f "image"="mysql:5.6" --since="1467302400" 
2016-07-11T00:38:53.975174837+08:00 container start 96f7f14e99ab9d2f60943a50be23035eda1623782cc5f930411bbea407a2bb10 (image=mysql:5.6, name=mymysql)
2016-07-11T00:51:17.022572452+08:00 container kill 96f7f14e99ab9d2f60943a50be23035eda1623782cc5f930411bbea407a2bb10 (image=mysql:5.6, name=mymysql, signal=9)
2016-07-11T00:51:17.132532080+08:00 container die 96f7f14e99ab9d2f60943a50be23035eda1623782cc5f930411bbea407a2bb10 (exitCode=137, image=mysql:5.6, name=mymysql)
2016-07-11T00:51:17.514661357+08:00 container destroy 96f7f14e99ab9d2f60943a50be23035eda1623782cc5f930411bbea407a2bb10 (image=mysql:5.6, name=mymysql)
2016-07-11T00:57:18.551984549+08:00 container create c8f0a32f12f5ec061d286af0b1285601a3e33a90a08ff1706de619ac823c345c (image=mysql:5.6, name=mymysql)
2016-07-11T00:57:18.557405864+08:00 container attach c8f0a32f12f5ec061d286af0b1285601a3e33a90a08ff1706de619ac823c345c (image=mysql:5.6, name=mymysql)
2016-07-11T00:57:18.844134112+08:00 container start c8f0a32f12f5ec061d286af0b1285601a3e33a90a08ff1706de619ac823c345c (image=mysql:5.6, name=mymysql)
2016-07-11T00:57:19.140141428+08:00 container die c8f0a32f12f5ec061d286af0b1285601a3e33a90a08ff1706de619ac823c345c (exitCode=1, image=mysql:5.6, name=mymysql)
2016-07-11T00:58:05.941019136+08:00 container destroy c8f0a32f12f5ec061d286af0b1285601a3e33a90a08ff1706de619ac823c345c (image=mysql:5.6, name=mymysql)
2016-07-11T00:58:07.965128417+08:00 container create a404c6c174a21c52f199cfce476e041074ab020453c7df2a13a7869b48f2f37e (image=mysql:5.6, name=mymysql)
2016-07-11T00:58:08.188734598+08:00 container start a404c6c174a21c52f199cfce476e041074ab020453c7df2a13a7869b48f2f37e (image=mysql:5.6, name=mymysql)
2016-07-11T00:58:20.010876777+08:00 container top a404c6c174a21c52f199cfce476e041074ab020453c7df2a13a7869b48f2f37e (image=mysql:5.6, name=mymysql)
2016-07-11T01:06:01.395365098+08:00 container top a404c6c174a21c52f199cfce476e041074ab020453c7df2a13a7869b48f2f37e (image=mysql:5.6, name=mymysql)
</code></pre>
<p>如果指定的时间是到秒级的，需要将时间转成时间戳。如果时间为日期的话，可以直接使用，如–since=”2016-07-01”。</p>
<h3 id="logs"><a href="#logs" class="headerlink" title="logs"></a>logs</h3><p><code>docker logs</code> : 获取容器的日志</p>
<h4 id="语法-12"><a href="#语法-12" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker logs [OPTIONS] CONTAINER
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li><p>-f : 跟踪日志输出</p>
</li>
<li><p>–since :显示某个开始时间的所有日志</p>
</li>
<li><p>-t : 显示时间戳</p>
</li>
<li><p>–tail :仅列出最新N条容器日志</p>
</li>
</ul>
<h4 id="实例-12"><a href="#实例-12" class="headerlink" title="实例"></a>实例</h4><p>跟踪查看容器mynginx的日志输出。</p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker logs -f mynginx
192.168.239.1 - - [10/Jul/2016:16:53:33 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36" "-"
2016/07/10 16:53:33 [error] 5#5: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.239.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.239.130", referrer: "http://192.168.239.130/"
192.168.239.1 - - [10/Jul/2016:16:53:33 +0000] "GET /favicon.ico HTTP/1.1" 404 571 "http://192.168.239.130/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36" "-"
192.168.239.1 - - [10/Jul/2016:16:53:59 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36" "-"
...
</code></pre>
<p>查看容器mynginx从2016年7月1日后的最新10条日志。</p>
<pre class=" language-shell"><code class="language-shell">docker logs --since="2016-07-01" --tail=10 mynginx
</code></pre>
<h3 id="wait"><a href="#wait" class="headerlink" title="wait"></a>wait</h3><p><code>docker wait</code> : 阻塞运行直到容器停止，然后打印出它的退出代码。</p>
<h4 id="语法-13"><a href="#语法-13" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker wait [OPTIONS] CONTAINER [CONTAINER...]
</code></pre>
<h4 id="实例-13"><a href="#实例-13" class="headerlink" title="实例"></a>实例</h4><pre class=" language-shell"><code class="language-shell">docker wait CONTAINER
</code></pre>
<h3 id="export"><a href="#export" class="headerlink" title="export"></a>export</h3><p>`docker export :将文件系统作为一个tar归档文件导出到STDOUT。</p>
<h4 id="语法-14"><a href="#语法-14" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker export [OPTIONS] CONTAINER
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li>-o :将输入内容写到文件。</li>
</ul>
<h4 id="实例-14"><a href="#实例-14" class="headerlink" title="实例"></a>实例</h4><p>将id为a404c6c174a2的容器按日期保存为tar文件。</p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker export -o mysql-`date +%Y%m%d`.tar a404c6c174a2
funga@funga:~$ ls mysql-`date +%Y%m%d`.tar
mysql-20160711.tar
</code></pre>
<h3 id="port"><a href="#port" class="headerlink" title="port"></a>port</h3><p><code>docker port</code> :列出指定的容器的端口映射，或者查找将PRIVATE_PORT NAT到面向公众的端口。</p>
<h4 id="语法-15"><a href="#语法-15" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker port [OPTIONS] CONTAINER [PRIVATE_PORT[/PROTO]]
</code></pre>
<h4 id="实例-15"><a href="#实例-15" class="headerlink" title="实例"></a>实例</h4><p>查看容器mynginx的端口映射情况。</p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker port mymysql
3306/tcp -> 0.0.0.0:3306
</code></pre>
<h2 id="容器rootfs命令"><a href="#容器rootfs命令" class="headerlink" title="容器rootfs命令"></a>容器rootfs命令</h2><h3 id="commit"><a href="#commit" class="headerlink" title="commit"></a>commit</h3><p><code>docker commit</code> :从容器创建一个新的镜像。</p>
<h4 id="语法-16"><a href="#语法-16" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li><p>-a :提交的镜像作者；</p>
</li>
<li><p>-c :使用Dockerfile指令来创建镜像；</p>
</li>
<li><p>-m :提交时的说明文字；</p>
</li>
<li><p>-p :在commit时，将容器暂停。</p>
</li>
</ul>
<h4 id="实例-16"><a href="#实例-16" class="headerlink" title="实例"></a>实例</h4><p>将容器a404c6c174a2 保存为新的镜像,并添加提交人信息和说明信息。</p>
<h3 id="cp"><a href="#cp" class="headerlink" title="cp"></a>cp</h3><p><code>docker cp</code> :用于容器与主机之间的数据拷贝。</p>
<h4 id="语法-17"><a href="#语法-17" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li>-L :保持源目标中的链接</li>
</ul>
<h4 id="实例-17"><a href="#实例-17" class="headerlink" title="实例"></a>实例</h4><p>将主机/www/funga目录拷贝到容器96f7f14e99ab的/www目录下。</p>
<pre class=" language-shell"><code class="language-shell">docker cp /www/funga 96f7f14e99ab:/www/
</code></pre>
<p>将主机/www/funga目录拷贝到容器96f7f14e99ab中，目录重命名为www。</p>
<pre class=" language-shell"><code class="language-shell">docker cp /www/funga 96f7f14e99ab:/www
</code></pre>
<p>将容器96f7f14e99ab的/www目录拷贝到主机的/tmp目录中。</p>
<pre class=" language-shell"><code class="language-shell">docker cp  96f7f14e99ab:/www /tmp/
</code></pre>
<h3 id="diff"><a href="#diff" class="headerlink" title="diff"></a>diff</h3><p><code>docker diff</code> : 检查容器里文件结构的更改。</p>
<h4 id="语法-18"><a href="#语法-18" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker diff [OPTIONS] CONTAINER
</code></pre>
<h4 id="实例-18"><a href="#实例-18" class="headerlink" title="实例"></a>实例</h4><p>查看容器mymysql的文件结构更改。</p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker diff mymysql
A /logs
A /mysql_data
C /run
C /run/mysqld
A /run/mysqld/mysqld.pid
A /run/mysqld/mysqld.sock
C /tmp
</code></pre>
<h2 id="镜像仓库"><a href="#镜像仓库" class="headerlink" title="镜像仓库"></a>镜像仓库</h2><h3 id="login"><a href="#login" class="headerlink" title="login"></a>login</h3><p><code>docker login</code> : 登陆到一个Docker镜像仓库，如果未指定镜像仓库地址，默认为官方仓库 Docker Hub</p>
<p><code>docker logout</code> : 登出一个Docker镜像仓库，如果未指定镜像仓库地址，默认为官方仓库 Docker Hub</p>
<h4 id="语法-19"><a href="#语法-19" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker login [OPTIONS] [SERVER]
docker logout [OPTIONS] [SERVER]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li><p>-u :登陆的用户名</p>
</li>
<li><p>-p :登陆的密码</p>
</li>
</ul>
<h4 id="实例-19"><a href="#实例-19" class="headerlink" title="实例"></a>实例</h4><p>登陆到Docker Hub</p>
<pre class=" language-shell"><code class="language-shell">docker login -u 用户名 -p 密码
</code></pre>
<p>登出Docker Hub</p>
<pre class=" language-shell"><code class="language-shell">docker logout
</code></pre>
<h3 id="pull"><a href="#pull" class="headerlink" title="pull"></a>pull</h3><p><code>docker pull</code> : 从镜像仓库中拉取或者更新指定镜像</p>
<h4 id="语法-20"><a href="#语法-20" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker pull [OPTIONS] NAME[:TAG|@DIGEST]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<p>-a :拉取所有 tagged 镜像</p>
<p>–disable-content-trust :忽略镜像的校验,默认开启</p>
<h4 id="实例-20"><a href="#实例-20" class="headerlink" title="实例"></a>实例</h4><p>从Docker Hub下载java最新版镜像。</p>
<pre class=" language-shell"><code class="language-shell">docker pull java
</code></pre>
<p>从Docker Hub下载REPOSITORY为java的所有镜像。</p>
<pre class=" language-shell"><code class="language-shell">docker pull -a java
</code></pre>
<h3 id="push"><a href="#push" class="headerlink" title="push"></a>push</h3><p><code>docker push</code> : 将本地的镜像上传到镜像仓库,要先登陆到镜像仓库</p>
<h4 id="语法-21"><a href="#语法-21" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker push [OPTIONS] NAME[:TAG]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li>–disable-content-trust :忽略镜像的校验,默认开启</li>
</ul>
<h4 id="实例-21"><a href="#实例-21" class="headerlink" title="实例"></a>实例</h4><p>上传本地镜像myapache:v1到镜像仓库中。</p>
<pre class=" language-shell"><code class="language-shell">docker push myapache:v1
</code></pre>
<h3 id="search"><a href="#search" class="headerlink" title="search"></a>search</h3><p>docker search : 从Docker Hub查找镜像</p>
<h4 id="语法-22"><a href="#语法-22" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker search [OPTIONS] TERM
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li><p>–automated :只列出 automated build类型的镜像；</p>
</li>
<li><p>–no-trunc :显示完整的镜像描述；</p>
</li>
<li><p>-s :列出收藏数不小于指定值的镜像。</p>
</li>
</ul>
<h4 id="实例-22"><a href="#实例-22" class="headerlink" title="实例"></a>实例</h4><p>从Docker Hub查找所有镜像名包含java，并且收藏数大于10的镜像</p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker search -s 10 java
NAME                  DESCRIPTION                           STARS   OFFICIAL   AUTOMATED
java                  Java is a concurrent, class-based...   1037    [OK]       
anapsix/alpine-java   Oracle Java 8 (and 7) with GLIBC ...   115                [OK]
develar/java                                                 46                 [OK]
isuper/java-oracle    This repository contains all java...   38                 [OK]
lwieske/java-8        Oracle Java 8 Container - Full + ...   27                 [OK]
nimmis/java-centos    This is docker images of CentOS 7...   13                 [OK]
</code></pre>
<h2 id="本地镜像管理"><a href="#本地镜像管理" class="headerlink" title="本地镜像管理"></a>本地镜像管理</h2><h3 id="images"><a href="#images" class="headerlink" title="images"></a>images</h3><p><code>docker images</code> : 列出本地镜像。</p>
<h4 id="语法-23"><a href="#语法-23" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker images [OPTIONS] [REPOSITORY[:TAG]]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<p>-a :列出本地所有的镜像（含中间映像层，默认情况下，过滤掉中间映像层）；</p>
<p>–digests :显示镜像的摘要信息；</p>
<p>-f :显示满足条件的镜像；</p>
<p>–format :指定返回值的模板文件；</p>
<p>–no-trunc :显示完整的镜像信息；</p>
<p>-q :只显示镜像ID。</p>
<h4 id="实例-23"><a href="#实例-23" class="headerlink" title="实例"></a>实例</h4><p>查看本地镜像列表。</p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
mymysql                 v1                  37af1236adef        5 minutes ago       329 MB
funga/ubuntu           v4                  1c06aa18edee        2 days ago          142.1 MB
<none>                  <none>              5c6e1090e771        2 days ago          165.9 MB
httpd                   latest              ed38aaffef30        11 days ago         195.1 MB
alpine                  latest              4e38e38c8ce0        2 weeks ago         4.799 MB
mongo                   3.2                 282fd552add6        3 weeks ago         336.1 MB
redis                   latest              4465e4bcad80        3 weeks ago         185.7 MB
php                     5.6-fpm             025041cd3aa5        3 weeks ago         456.3 MB
python                  3.5                 045767ddf24a        3 weeks ago         684.1 MB
...
</none></none></code></pre>
<p>列出本地镜像中REPOSITORY为ubuntu的镜像列表。</p>
<pre class=" language-shell"><code class="language-shell">root@funga:~# docker images  ubuntu
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              14.04               90d5884b1ee0        9 weeks ago         188 MB
ubuntu              15.10               4e3b13c8a266        3 months ago        136.3 MB
</code></pre>
<h3 id="rmi"><a href="#rmi" class="headerlink" title="rmi"></a>rmi</h3><p><code>docker rmi</code> : 删除本地一个或多少镜像。</p>
<h4 id="语法-24"><a href="#语法-24" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker rmi [OPTIONS] IMAGE [IMAGE...]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<p>-f :强制删除；</p>
<p>–no-prune :不移除该镜像的过程镜像，默认移除；</p>
<h4 id="实例-24"><a href="#实例-24" class="headerlink" title="实例"></a>实例</h4><p>强制删除本地镜像funga/ubuntu:v4。</p>
<pre class=" language-shell"><code class="language-shell">root@funga:~# docker rmi -f funga/ubuntu:v4
Untagged: funga/ubuntu:v4
Deleted: sha256:1c06aa18edee44230f93a90a7d88139235de12cd4c089d41eed8419b503072be
Deleted: sha256:85feb446e89a28d58ee7d80ea5ce367eebb7cec70f0ec18aa4faa874cbd97c73
</code></pre>
<h3 id="tag"><a href="#tag" class="headerlink" title="tag"></a>tag</h3><p>docker tag : 标记本地镜像，将其归入某一仓库。</p>
<h4 id="语法-25"><a href="#语法-25" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
</code></pre>
<h4 id="实例-25"><a href="#实例-25" class="headerlink" title="实例"></a>实例</h4><p>将镜像ubuntu:15.10标记为 funga/ubuntu:v3 镜像。</p>
<pre class=" language-shell"><code class="language-shell">root@funga:~# docker tag ubuntu:15.10 funga/ubuntu:v3
root@funga:~# docker images   funga/ubuntu:v3
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
funga/ubuntu       v3                  4e3b13c8a266        3 months ago        136.3 MB
</code></pre>
<h3 id="build"><a href="#build" class="headerlink" title="build"></a>build</h3><p><code>docker build</code> 命令用于使用 Dockerfile 创建镜像。</p>
<h4 id="语法-26"><a href="#语法-26" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker build [OPTIONS] PATH | URL | -
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li><p>–build-arg=[] :设置镜像创建时的变量；</p>
</li>
<li><p>–cpu-shares :设置 cpu 使用权重；</p>
</li>
<li><p>–cpu-period :限制 CPU CFS周期；</p>
</li>
<li><p>–cpu-quota :限制 CPU CFS配额；</p>
</li>
<li><p>–cpuset-cpus :指定使用的CPU id；</p>
</li>
<li><p>–cpuset-mems :指定使用的内存 id；</p>
</li>
<li><p>–disable-content-trust :忽略校验，默认开启；</p>
</li>
<li><p>-f :指定要使用的Dockerfile路径；</p>
</li>
<li><p>–force-rm :设置镜像过程中删除中间容器；</p>
</li>
<li><p>–isolation :使用容器隔离技术；</p>
</li>
<li><p>–label=[] :设置镜像使用的元数据；</p>
</li>
<li><p>-m :设置内存最大值；</p>
</li>
<li><p>–memory-swap :设置Swap的最大值为内存+swap，”-1”表示不限swap；</p>
</li>
<li><p>–no-cache :创建镜像的过程不使用缓存；</p>
</li>
<li><p>–pull :尝试去更新镜像的新版本；</p>
</li>
<li><p>–quiet, -q :安静模式，成功后只输出镜像 ID；</p>
</li>
<li><p>–rm :设置镜像成功后删除中间容器；</p>
</li>
<li><p>–shm-size :设置/dev/shm的大小，默认值是64M；</p>
</li>
<li><p>–ulimit :Ulimit配置。</p>
</li>
<li><p>–tag, -t: 镜像的名字及标签，通常 name:tag 或者 name 格式；可以在一次构建中为一个镜像设置多个标签。</p>
</li>
<li><p>–network: 默认 default。在构建期间设置RUN指令的网络模式</p>
</li>
</ul>
<h4 id="实例-26"><a href="#实例-26" class="headerlink" title="实例"></a>实例</h4><p>使用当前目录的 Dockerfile 创建镜像，标签为 funga/ubuntu:v1。</p>
<pre class=" language-shell"><code class="language-shell">docker build -t funga/ubuntu:v1 . 
</code></pre>
<p>使用URL github.com/creack/docker-firefox 的 Dockerfile 创建镜像。</p>
<pre class=" language-shell"><code class="language-shell">docker build github.com/creack/docker-firefox
</code></pre>
<p>也可以通过 -f Dockerfile 文件的位置：</p>
<pre class=" language-shell"><code class="language-shell">$ docker build -f /path/to/a/Dockerfile .
</code></pre>
<p>在 Docker 守护进程执行 Dockerfile 中的指令前，首先会对 Dockerfile 进行语法检查，有语法错误时会返回：</p>
<pre class=" language-shell"><code class="language-shell">$ docker build -t test/myapp .
Sending build context to Docker daemon 2.048 kB
Error response from daemon: Unknown instruction: RUNCMD
</code></pre>
<h3 id="history"><a href="#history" class="headerlink" title="history"></a>history</h3><p><code>docker history</code> : 查看指定镜像的创建历史。</p>
<h4 id="语法-27"><a href="#语法-27" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker history [OPTIONS] IMAGE
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li><p>-H :以可读的格式打印镜像大小和日期，默认为true；</p>
</li>
<li><p>–no-trunc :显示完整的提交记录；</p>
</li>
<li><p>-q :仅列出提交记录ID。</p>
</li>
</ul>
<h4 id="实例-27"><a href="#实例-27" class="headerlink" title="实例"></a>实例</h4><p>查看本地镜像funga/ubuntu:v3的创建历史。</p>
<pre class=" language-shell"><code class="language-shell">root@funga:~# docker history funga/ubuntu:v3
IMAGE             CREATED           CREATED BY                                      SIZE      COMMENT
4e3b13c8a266      3 months ago      /bin/sh -c #(nop) CMD ["/bin/bash"]             0 B                 
<missing>         3 months ago      /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/   1.863 kB            
<missing>         3 months ago      /bin/sh -c set -xe   && echo '#!/bin/sh' > /u   701 B               
<missing>         3 months ago      /bin/sh -c #(nop) ADD file:43cb048516c6b80f22   136.3 MB
</missing></missing></missing></code></pre>
<h3 id="save"><a href="#save" class="headerlink" title="save"></a>save</h3><p><code>docker save</code> : 将指定镜像保存成 tar 归档文件。</p>
<h4 id="语法-28"><a href="#语法-28" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker save [OPTIONS] IMAGE [IMAGE...]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li>-o :输出到的文件。</li>
</ul>
<h4 id="实例-28"><a href="#实例-28" class="headerlink" title="实例"></a>实例</h4><p>将镜像funga/ubuntu:v3 生成my_ubuntu_v3.tar文档</p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker save -o my_ubuntu_v3.tar funga/ubuntu:v3
funga@funga:~$ ll my_ubuntu_v3.tar
-rw------- 1 funga funga 142102016 Jul 11 01:37 my_ubuntu_v3.ta
</code></pre>
<h3 id="import"><a href="#import" class="headerlink" title="import"></a>import</h3><p><code>docker import</code> : 从归档文件中创建镜像。</p>
<h4 id="语法-29"><a href="#语法-29" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
</code></pre>
<p><strong>OPTIONS说明：</strong></p>
<ul>
<li><p>-c :应用docker 指令创建镜像；</p>
</li>
<li><p>-m :提交时的说明文字；</p>
</li>
</ul>
<h4 id="实例-29"><a href="#实例-29" class="headerlink" title="实例"></a>实例</h4><p>从镜像归档文件my_ubuntu_v3.tar创建镜像，命名为funga/ubuntu:v4</p>
<pre class=" language-shell"><code class="language-shell">funga@funga:~$ docker import  my_ubuntu_v3.tar funga/ubuntu:v4  
sha256:63ce4a6d6bc3fabb95dbd6c561404a309b7bdfc4e21c1d59fe9fe4299cbfea39
funga@funga:~$ docker images funga/ubuntu:v4
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
funga/ubuntu       v4                  63ce4a6d6bc3        20 seconds ago      142.1 MB
</code></pre>
<h2 id="info-version"><a href="#info-version" class="headerlink" title="info|version"></a>info|version</h2><h3 id="info"><a href="#info" class="headerlink" title="info"></a>info</h3><p><code>docker info</code> : 显示 Docker 系统信息，包括镜像和容器数。</p>
<h4 id="语法-30"><a href="#语法-30" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker info [OPTIONS]
</code></pre>
<h4 id="实例-30"><a href="#实例-30" class="headerlink" title="实例"></a>实例</h4><p><em>查看docker系统信息</em></p>
<pre class=" language-shell"><code class="language-shell">$ docker info
Containers: 12
Images: 41
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 66
 Dirperm1 Supported: false
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.13.0-32-generic
Operating System: Ubuntu 14.04.1 LTS
CPUs: 1
Total Memory: 1.954 GiB
Name: iZ23mtq8bs1Z
ID: M5N4:K6WN:PUNC:73ZN:AONJ:AUHL:KSYH:2JPI:CH3K:O4MK:6OCX:5OYW
</code></pre>
<h3 id="version"><a href="#version" class="headerlink" title="version"></a>version</h3><p><code>docker version</code> :显示 Docker 版本信息</p>
<h4 id="语法-31"><a href="#语法-31" class="headerlink" title="语法"></a>语法</h4><pre class=" language-shell"><code class="language-shell">docker version [OPTIONS]
</code></pre>
<p><strong>OPTIONS说明</strong></p>
<ul>
<li>-f :指定返回值的模板文件</li>
</ul>
<h4 id="实例-31"><a href="#实例-31" class="headerlink" title="实例"></a>实例</h4><p><em>显示 Docker 版本信息</em></p>
<pre class=" language-shell"><code class="language-shell">Client:
 Version:      1.8.2
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   0a8c2e3
 Built:        Thu Sep 10 19:19:00 UTC 2015
 OS/Arch:      linux/amd64

Server:
 Version:      1.8.2
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   0a8c2e3
 Built:        Thu Sep 10 19:19:00 UTC 2015
 OS/Arch:      linux/amd64
</code></pre>

      
    </div>
    <footer class="entry-meta entry-footer">
      
	<span class="ico-folder"></span>
    <a class="article-category-link" href="/categories/其它分类/">其它分类</a>

      
  <span class="ico-tags"></span>
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/docker/">docker</a></li></ul>

      
        <div id="donation_div"></div>

<script src="/js/vdonate.js"></script>
<script>
var a = new Donate({
  title: '如果觉得我的文章对您有用，请随意打赏。您的支持将鼓励我继续创作!', // 可选参数，打赏标题
  btnText: 'Donate', // 可选参数，打赏按钮文字
  el: document.getElementById('donation_div'),
  wechatImage: 'https://funga.oss-cn-beijing.aliyuncs.com/config/wechat_pay_code.jpg',
  alipayImage: 'https://funga.oss-cn-beijing.aliyuncs.com/config/alipay_code.png'
});
</script>
      
            
      
        <!--PC版-->
<div id="SOHUCS"></div>
<!-- <script charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/changyan.js" ></script> -->
<script charset="utf-8" type="text/javascript" src="https://funga.oss-cn-beijing.aliyuncs.com/static/changyan.js"></script>
<script type="text/javascript">
window.changyan.api.config({
appid: 'cyrV0wIGI',
conf: 'prod_3d29a99dcddb3782e98f1fa951b9868f'
});
</script>
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2017/12/20/vim-cmd/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          vim常用快捷键大全
        
      </div>
    </a>
  
  
    <a href="/2017/12/14/git/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Git 常用命令大全</div>
    </a>
  
</nav>

  
</article>

<!-- Table of Contents -->

  <aside id="sidebar">
    <div id="toc" class="toc-article" style="overflow-y: scroll; max-width: 28%;">
    <strong class="toc-title">Contents</strong>
    
      <ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#容器生命周期管理"><span class="nav-number">1.</span> <span class="nav-text">容器生命周期管理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#run"><span class="nav-number">1.1.</span> <span class="nav-text">run</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法"><span class="nav-number">1.1.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例"><span class="nav-number">1.1.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#start-stop-restart"><span class="nav-number">1.2.</span> <span class="nav-text">start/stop/restart</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-1"><span class="nav-number">1.2.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-1"><span class="nav-number">1.2.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#kill"><span class="nav-number">1.3.</span> <span class="nav-text">kill</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-2"><span class="nav-number">1.3.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-2"><span class="nav-number">1.3.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#rm"><span class="nav-number">1.4.</span> <span class="nav-text">rm</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-3"><span class="nav-number">1.4.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-3"><span class="nav-number">1.4.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#pause-unpause"><span class="nav-number">1.5.</span> <span class="nav-text">pause/unpause</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-4"><span class="nav-number">1.5.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-4"><span class="nav-number">1.5.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#create"><span class="nav-number">1.6.</span> <span class="nav-text">create</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-5"><span class="nav-number">1.6.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-5"><span class="nav-number">1.6.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#exec"><span class="nav-number">1.7.</span> <span class="nav-text">exec</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-6"><span class="nav-number">1.7.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-6"><span class="nav-number">1.7.2.</span> <span class="nav-text">实例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#容器操作"><span class="nav-number">2.</span> <span class="nav-text">容器操作</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#ps"><span class="nav-number">2.1.</span> <span class="nav-text">ps</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-7"><span class="nav-number">2.1.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-7"><span class="nav-number">2.1.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#inspect"><span class="nav-number">2.2.</span> <span class="nav-text">inspect</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-8"><span class="nav-number">2.2.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-8"><span class="nav-number">2.2.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#top"><span class="nav-number">2.3.</span> <span class="nav-text">top</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-9"><span class="nav-number">2.3.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-9"><span class="nav-number">2.3.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#attach"><span class="nav-number">2.4.</span> <span class="nav-text">attach</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-10"><span class="nav-number">2.4.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-10"><span class="nav-number">2.4.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#events"><span class="nav-number">2.5.</span> <span class="nav-text">events</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-11"><span class="nav-number">2.5.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-11"><span class="nav-number">2.5.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#logs"><span class="nav-number">2.6.</span> <span class="nav-text">logs</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-12"><span class="nav-number">2.6.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-12"><span class="nav-number">2.6.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#wait"><span class="nav-number">2.7.</span> <span class="nav-text">wait</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-13"><span class="nav-number">2.7.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-13"><span class="nav-number">2.7.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#export"><span class="nav-number">2.8.</span> <span class="nav-text">export</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-14"><span class="nav-number">2.8.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-14"><span class="nav-number">2.8.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#port"><span class="nav-number">2.9.</span> <span class="nav-text">port</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-15"><span class="nav-number">2.9.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-15"><span class="nav-number">2.9.2.</span> <span class="nav-text">实例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#容器rootfs命令"><span class="nav-number">3.</span> <span class="nav-text">容器rootfs命令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#commit"><span class="nav-number">3.1.</span> <span class="nav-text">commit</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-16"><span class="nav-number">3.1.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-16"><span class="nav-number">3.1.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#cp"><span class="nav-number">3.2.</span> <span class="nav-text">cp</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-17"><span class="nav-number">3.2.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-17"><span class="nav-number">3.2.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#diff"><span class="nav-number">3.3.</span> <span class="nav-text">diff</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-18"><span class="nav-number">3.3.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-18"><span class="nav-number">3.3.2.</span> <span class="nav-text">实例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#镜像仓库"><span class="nav-number">4.</span> <span class="nav-text">镜像仓库</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#login"><span class="nav-number">4.1.</span> <span class="nav-text">login</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-19"><span class="nav-number">4.1.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-19"><span class="nav-number">4.1.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#pull"><span class="nav-number">4.2.</span> <span class="nav-text">pull</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-20"><span class="nav-number">4.2.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-20"><span class="nav-number">4.2.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#push"><span class="nav-number">4.3.</span> <span class="nav-text">push</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-21"><span class="nav-number">4.3.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-21"><span class="nav-number">4.3.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#search"><span class="nav-number">4.4.</span> <span class="nav-text">search</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-22"><span class="nav-number">4.4.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-22"><span class="nav-number">4.4.2.</span> <span class="nav-text">实例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#本地镜像管理"><span class="nav-number">5.</span> <span class="nav-text">本地镜像管理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#images"><span class="nav-number">5.1.</span> <span class="nav-text">images</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-23"><span class="nav-number">5.1.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-23"><span class="nav-number">5.1.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#rmi"><span class="nav-number">5.2.</span> <span class="nav-text">rmi</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-24"><span class="nav-number">5.2.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-24"><span class="nav-number">5.2.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#tag"><span class="nav-number">5.3.</span> <span class="nav-text">tag</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-25"><span class="nav-number">5.3.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-25"><span class="nav-number">5.3.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#build"><span class="nav-number">5.4.</span> <span class="nav-text">build</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-26"><span class="nav-number">5.4.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-26"><span class="nav-number">5.4.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#history"><span class="nav-number">5.5.</span> <span class="nav-text">history</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-27"><span class="nav-number">5.5.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-27"><span class="nav-number">5.5.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#save"><span class="nav-number">5.6.</span> <span class="nav-text">save</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-28"><span class="nav-number">5.6.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-28"><span class="nav-number">5.6.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#import"><span class="nav-number">5.7.</span> <span class="nav-text">import</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-29"><span class="nav-number">5.7.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-29"><span class="nav-number">5.7.2.</span> <span class="nav-text">实例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#info-version"><span class="nav-number">6.</span> <span class="nav-text">info|version</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#info"><span class="nav-number">6.1.</span> <span class="nav-text">info</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-30"><span class="nav-number">6.1.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-30"><span class="nav-number">6.1.2.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#version"><span class="nav-number">6.2.</span> <span class="nav-text">version</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#语法-31"><span class="nav-number">6.2.1.</span> <span class="nav-text">语法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实例-31"><span class="nav-number">6.2.2.</span> <span class="nav-text">实例</span></a></li></ol></li></ol></li></ol>
    
    </div>
  </aside>
</section>
        
      </div>
      <footer id="footer" class="site-footer">
  

  <div class="clearfix container">
      <div class="site-info">
	      &copy; 2019 FunGa技术札记 All Rights Reserved.
          
            <span id="busuanzi_container_site_uv">
              本站访客数<span id="busuanzi_value_site_uv"></span>人次  
              本站总访问量<span id="busuanzi_value_site_pv"></span>次
            </span>
          
      </div>
      <div class="site-credit">
        Theme by <a href="https://github.com/iTimeTraveler/hexo-theme-hiero" target="_blank">hiero</a>
      </div>
  </div>
</footer>


<!-- min height -->

<script>
    var contentdiv = document.getElementById("content");

    contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("allheader").offsetHeight - document.getElementById("footer").offsetHeight + "px";
</script>

<!-- Custome JS -->
<script src="/js/my.js"></script>
    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/categories" class="mobile-nav-link">Categories</a>
  
    <a href="/tags" class="mobile-nav-link">Tags</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav> -->
    

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>



  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.js"></script>


<script src="/js/scripts.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="/js/main.js"></script>







  <div style="display: none;">
    <script src="https://s95.cnzz.com/z_stat.php?id=1260716016&web_id=1260716016" language="JavaScript"></script>
  </div>



	<script async src="https://dnqof95d40fo6.cloudfront.net/atw7f8.js">
	</script>






  </div>

  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/js/totop.js" async=""></script>
</body>
</html>
